<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$info=$return['pluginset'];
	//从请求参数中获取code
	$code=$_RQ['code'];
	if(!$code){
		$message['error']=2;
	}else{
		//code被查询次数
		$count=pdo_count('jy_goodserpfw_log',array('uniacid'=>$_SESSION['uniacid'],'code'=>$code,'merchid'=>$_SESSION['onemerchid']));
		$isfirst=$count==0?1:0;
		$secury=$this->plugin_setting('secury');
		$logid=$this->check_code($code);
		$message['error'] = $logid?0:1;
		if($message['error'] == 0){
			$message['msg']='该产品属于正品！请放心使用！';
			$num=$secury['num'];
			if($num && $num<=$count){
				$message['error']=1;
				$message['msg']='O~该产品属于正品！但超过查询次数！';
			}
            $count++;
            $goods_id=pdo_getcolumn('jy_goodserpfw_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$logid),'goods_id');
            $info['goods_title']=pdo_getcolumn('jy_goodserpfw_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$goods_id),'title');
		}else{
			$message['msg']='O~！该产品非正品！';
		}
	}
    $info['count']=$count;
	$return['url']=custom_url('jy_goodserpfw/search/main/',true);
	$return['info']=$info;
	$return['message']=$message;
	set_html('title','在线防伪溯源查询');
	exi($return);
}
if($_RQ['op']=='check_status'){
	$post=get_postdata();
	if(!$_RQ['nowcode']){
		$res['isnonowcode']=1;
		exi($res);
	}
	$ismerch=intval($_RQ['ismerch']);
	$nowcode=trim($_RQ['nowcode']);
	$type=$post['type'];
	$code_type=1;
	if($post['type']==6){
		$type=0;
		$code_type=0;
	}elseif($post['type']==10){
		$type=1;
		$code_type=0;
	}elseif($post['type']==30){
		$type=3;
		$code_type=0;
	}
	if($_RQ['iszhuang']){
		$code_type=0;
	}
	$log=array(
		'type'=>$type,
		'code'=>$nowcode,
		'code_type'=>$code_type,
	);
	//print_r($log);exit;
	$msg=$this->model('model')->check_status($log,$ismerch,true);
	$res['success']=$msg?0:1;
	$res['msg']=$msg;
	exi($res);
}
?>